var app = getApp();
Page({
    data: {
        bgimage: "/hyb_jianzhi/images/agenttop.png",
        btmimage: "/hyb_jianzhi/images/agentbtm.png",
        imgHeight:'',
        region: [],
        array: [],
        index:0,
        userN:'',
        passW:'',
        cityName:''
    },
    onLoad: function(n) {
        var self = this,g_id=n.g_id;
        console.log("代理项目id"+g_id);
        self.setData({
            g_id:g_id
        });
        var wHeight=wx.getSystemInfoSync().windowHeight
        self.setData({
            imgHeight:wHeight
        });
        self.loadAgentArea();
    },
    loadAgentArea:function(){
        var self = this;
         app.util.request({
            url: "entry/wxapp/Getshangquan",
            data: {
                id: 0,
            },
            success: function(n) {
                console.log("城市"+JSON.stringify(n))
                self.setData({
                    array:n.data.data
                })
            }
        });
         
    },
    bindRegionChange: function(a) {
        var self = this;
         self.setData({
            index: a.detail.value
         });
         self.setData({
           cityName: self.data.array[self.data.index].name
         });
     },
      //用户名和密码输入框事件
  userNameInput:function(e){
    this.setData({
      userN:e.detail.value
    })
  },
  userPhoneInput:function(e){
    this.setData({
      passW:e.detail.value
    })
  },
  formAgent:function(){
        var self = this;
        app.util.request({
            url: "entry/wxapp/Hz_daili",
            data:{
                    username: self.data.userN,
                    mobile: self.data.passW,
                    openid:wx.getStorageSync("openid"),
                    city: self.data.cityName,
                    goodsid:self.data.g_id
            },
            success: function() {
                wx.showToast({
                   title: '申请成功!请耐心等待审核。'
                });
                setTimeout(function(){
                     wx.reLaunch({
                        url: "/hyb_jianzhi/index/index"
                    });
                },500)
            }
        })
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {}
});